<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	//表格动态Id
	request.setAttribute("sn_id", (int) (Math.random() * 100000));
	// 
	if (request.getParameter("setValue") == null) {
		request.setAttribute("setValue", "setValue");
	} else {
		request.setAttribute("setValue",
				"" + request.getParameter("setValue"));
	}// 
	if (request.getParameter("func") == null) {
		request.setAttribute("func", "func");
	} else {
		request.setAttribute("func",
				"" + request.getParameter("func"));
	}// 
	if (request.getParameter("getValue") == null) {
		request.setAttribute("getValue", "getValue");
	} else {
		request.setAttribute("getValue",
				"" + request.getParameter("getValue"));
	}// 
	if (request.getParameter("getGant") == null) {
		request.setAttribute("getGant", "getGant");
	} else {
		request.setAttribute("getGant",
				"" + request.getParameter("getGant"));
	}
	request.setAttribute("sessionId", "" + request.getSession().getId());
%>
<script type="text/javascript">
$(function (){
	initGant_${sn_id}();
});
function initGant_${sn_id}(){
	//设置视图
	gantt.config.scale_unit = "day";
	//设置日期最小度
	gantt.config.date_scale = "%d";
	gantt.config.subscales = [
	                  		{unit:"month", step:1, date:"%Y年%m月" }
	                		,{unit:"week", step:1, date:"%Y年%W周" }
	                		//,{unit:"hour", step:6, date:"%H:%i"}

	];

	//设置时间格式
	gantt.config.xml_date = "%Y-%m-%d %H:%i:%s";
	//设置首行高度
	gantt.config.scale_height = 40;
	/////////////设置周末背景色///////////////
	gantt.templates.scale_cell_class = function(date){
		if(date.getDay()==0||date.getDay()==6){
			return "weekend";
		}
	};
	gantt.templates.task_cell_class = function(item,date){
		if(date.getDay()==0||date.getDay()==6){
			return "weekend" ;
		}
	};
	gantt.config.work_time = true;
///////////////////设置开始赶时间与结束时间//////////////
// 	gantt.config.start_date = new Date(2013, 02, 31);
// 	gantt.config.end_date = new Date(2015, 03, 09);
// gantt.locale.labels['type_' + "customType"] = "New Type";
//设置自动排程
	gantt.config.auto_scheduling = true;
	gantt.config.auto_scheduling_strict = true;
	gantt.attachEvent("onBeforeAutoSchedule", function(){
		gantt.message("Recalculating project schedule...");
		return true;
	});
	gantt.attachEvent("onAfterTaskAutoSchedule", function(task, new_date, constraint, predecessor){
		gantt.message({
			text: "<b>"+task.text+"</b> has been rescheduled to " + gantt.templates.task_date(new_date) + " due to <b>"+predecessor.text+"</b> constraint",
			expire:4000
		});
	});

//////////////
	gantt.templates.progress_text = function(start, end, task){
// 	return "12";
		return "<div style='color:#11efef;width:100%;text-align:left;'>"+Math.round(task.progress*100)+ "% </div>";
	};

//////////////设置不可移动
gantt.config.drag_move = false;
gantt.config.drag_lightbox = false;
gantt.config.drag_links = false;
gantt.config.drag_progress = false;
gantt.config.drag_resize = false;
//////////////
// gantt.config.readonly = true;
//////////////
gantt.attachEvent("onTaskDblClick", function(id,e){
    //any custom logic here
	${func}(id);
    return false;
});
gantt.attachEvent("onLinkDblClick", function(id,e){
    //any custom logic here
    return false;
});
//////////////
//////////////

	var colHeader = '<div class="gantt_grid_head_cell gantt_grid_head_add" onclick="gantt.createTask()"></div>',
		colContent = function(task){
			return ('<i onclick="clickGridButton(\''+task.id+'\', \'view\')">#</i>');
			
					//'<button style="width:20px" class="fa gantt_button_grid gantt_grid_add fa-plus" onclick="clickGridButton('+task.id+', \'add\')"></button>' +
					//'<button style="width:20px" class="fa gantt_button_grid gantt_grid_delete fa-times" onclick="clickGridButton('+task.id+', \'delete\')"></button>'+
// 					'<button style="width:20px;height:20px;" class="fa gantt_button_grid gantt_grid_delete fa-times" onclick="clickGridButton('+task.id+', \'view\')">V</button>');
		};
		//设置列信息
	gantt.config.columns = [
		{name:"text", tree:true, width:'*', resize:true },
		{name:"start_date", align: "center", resize:true },
		{name:"duration", align: "center" },
		{
			name:"buttons",
			label : colHeader,
			width:40,
			template:colContent
		}
	];
	//初始化
	gantt.init("mygantter_${sn_id}");
	
}
function ${getGant}(){
return gantt;	
}
function ${setValue}(json){
	${getGant}().parse(json);
	
}
function clickGridButton(id, action) {
		switch (action) {
			case "edit":
				gantt.showLightbox(id);
				break;
			case "add":
				gantt.createTask(null, id);
				break;
			case "delete":
				gantt.confirm({
					title: gantt.locale.labels.confirm_deleting_title,
					text: gantt.locale.labels.confirm_deleting,
					callback: function(res){
						if(res)
							gantt.deleteTask(id);
					}
				});
				break;
			case "view":
				gantt.showLightbox(id);
					break;
		}
	}

</script>
<style type="text/css">
.weekend {
	background: #f4f7f4 !important;
}
</style>
<table style="width:98%;height:100%;margin-left:auto;margin-right:auto;" border="0">
	<tr class="footerCont" style="height: 5px">
		<td></td>
	</tr>
	<tr style="height: AUTO;">
		<td>
			<div id="mygantter_${sn_id}" style='width:100%; height:100%;'></div>
		</td>
	</tr>
</table>
